package com.salim.leetcode.$69;

public class Sqrtx {
    int start = 1;
    int end = 46340;
    public int mySqrt(int x) {
        if(x==0){
            return 0;
        }
        if(x>=2147395600){
            return 46340;
        }
        while (true){
            int middle = (start+end)/2;
            if(middle*middle>x){
                if(end-start==1){
                    return start;
                }
                end = middle;
            }else if(middle*middle==x){
                return middle;
            }else if(middle*middle<x){
                if(end-start==1){
                    return start;
                }
                start = middle;
            }
        }
    }
    public static void main(String[] args) {
        Sqrtx s = new Sqrtx();
        s.mySqrt(10);
    }
}
